package com.elitesland.metadata.rest;

import com.elitesland.core.base.ApiResult;
import com.elitesland.metadata.service.MetaCatService;
import com.elitesland.metadata.vo.MetaCatDefVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <pre>作用说明</pre>
 *
 * @author mir
 * @date 11/28/2020 11:52 PM
 */
@RestController
@RequestMapping("/metacat")
@Api(value = "元数据管理", tags = {"自选分类管理"})
public class MetaCatController {

    private MetaCatService metaCatService;

    @Autowired
    public void setMetaCatService(MetaCatService metaCatService) {
        this.metaCatService = metaCatService;
    }

    @GetMapping("/bytree/itm")
    @ApiOperation("商品自选分类树：3-1-2")
    public ApiResult<Object> testTree() {
        val fields = new MetaCatDefVO[]{
                new MetaCatDefVO().setFieldName("item_type3")
                        .setDomainCode("ITM").setUdcCode("ITEM_TYPE3"),
                new MetaCatDefVO().setFieldName("item_type4")
                        .setDomainCode("ITM").setUdcCode("ITEM_TYPE4"),
                new MetaCatDefVO().setFieldName("item_type5")
                        .setDomainCode("ITM").setUdcCode("ITEM_TYPE5")
        };
        val nodes = metaCatService.listCatTree("itm_item", fields);
        return ApiResult.ok(nodes);
    }

    @GetMapping("/bytree/{code}")
    @ApiOperation("根据定义表，获取分类树")
    public ApiResult<Object> listTreeByTableCode(@PathVariable String code) {
        val nodes = metaCatService.listCatTreeByTableCode(code);
        return ApiResult.ok(nodes);
    }
}
